<?php

namespace App\Services\MakeMoment;

use App\Models\User;
use App\Models\MomentComment;
use App\Models\MomentReply;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;

class ReplyMoment
{
	protected $user;
	
	protected $momentComment;

	protected $replyId;

	protected $content;
	
	public function __construct(User $user, MomentComment $momentComment,$replyId = 0,$content = null )
	{
		$this->user = $user;
		$this->momentComment = $momentComment;
		$this->replyId = $replyId;
		$this->content = $content;
	}
	
	
	
	protected function reply()
	{

		$moment = DB::transaction(function () {
			
			$data = [
				'moment_comment_id' => $this->momentComment->id,
				'parent_moment_reply_id' => $this->replyId,
				'content' => $this->content
			];

			$moment = $this->user->momentReplies()->create($data);
			return $moment;
		});
		
		return $moment;
	}
	
	public function create()
	{
		return $this->reply();
	}
}
